﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using INHSStudentRegistration;

namespace IrisanNHS
{
    public partial class Form4 : Form
    {
        MainForm parent;

        DataBaseConnection DBCN = new DataBaseConnection();
        public DataTable DT = new DataTable();
        public int InDeX;

        public Form4(MainForm p)
        {
            InitializeComponent();
            parent = p;
            this.Load += new EventHandler(Form4_Load);
            btnSearch.Click +=new EventHandler(btnSearch_Click);
            txtsearch.TextChanged +=new EventHandler(txtsearch_TextChanged);
            dataGridView.Click +=new EventHandler(dataGridView_Click);
        }

        void dataGridView_Click(object sender, EventArgs e)
        {
            if (dataGridView.Rows.Count != 0)
            {
                InDeX = dataGridView.SelectedRows[0].Index;
            }
        }

        void txtsearch_TextChanged(object sender, EventArgs e)
        {
            Search();
        }

        void Form4_Load(object sender, EventArgs e)
        {
            DBCN.DBConnection();
            DBCN.MyQuery("SELECT * FROM irisansrtable");
            DT = DBCN.DT;
            dataGridView.DataSource = DT;
            DBCN.Close();
        }

        private void Search()
        {
            string mysql = "SELECT * FROM IrisanSRTable WHERE Like '%" + txtsearch + "%'";
            DBCN.MyQuery(mysql);
            DT = DBCN.DT;
            dataGridView.DataSource = DT;
        }

        void btnSearch_Click(object sender, EventArgs e)
        {
            Search();
        }
    }
}
